import { urlPrefix as PointUrlPrefix } from "@/views/iot/point/api";
export const crudOptions = (vm) => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      width: '100%',
      height: '100%' // 表格高度100%, 使用toolbar必须设置
    },
    rowHandle: {
      edit: {
        thin: true,
        text: '编辑',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '删除',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      }
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      disabled: true,
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 24, // 默认的表单 span
      width: '35%'
    },
    columns: [
      {
        title: '所属点位',
        key: 'point',
        type: 'select',
        search: {
          disabled: false
        },
        dict: {
          cache: true,
          url: PointUrlPrefix + '?limit=999',
          label: 'name',
          value: 'id'
        },
        form: {
          rules: [
            { required: true, message: '请选择点位' }
          ],
          component: {
            placeholder: '请选择点位'
          }
        }
      },
      {
        title: '类型',
        key: 'type',
        type: 'select',
        search: {
          disabled: false
        },
        dict: {
          data: [{ label: '预警', value: 0 }, { label: '报警', value: 1 }]
        },
        form: {
          rules: [
            { required: true, message: '报警类型' }
          ],
          component: {
            placeholder: '请选择报警类型'
          }
        }
      },
      {
        title: '值',
        key: 'value',
        type: 'number',
        search: {
          disabled: true
        },
        form: {
          rules: [
            { required: true, message: '报警值' }
          ],
          component: {
            placeholder: '填写报警值'
          }
        }
      }
    ]
  }
}
